/*
 * Copyright 2009 Gal Dolber
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.gwt.user.dragdrop.client.util;

import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.dragdrop.client.DragController;
import com.google.gwt.user.dragdrop.client.HasDragHandlers;

/**
 * Empty Drag Implementation
 */
public class DragHandler implements HasDragHandlers {

	/**
	 * Valid the 
	 * @param controller
	 * @param ValidButton 
	 * @return
	 */
	public boolean validButton(DragController controller, MouseButton ValidButton) {
		switch (ValidButton) {
		
		case BUTTON_ALL: {
			return true;
		}
		
		case BUTTON_LEFT: {
			if (controller.getButton()==NativeEvent.BUTTON_LEFT) {
				return true;
			} else {
				return false;
			}
		}
		
		case BUTTON_MIDDLE: {
			if (controller.getButton()==NativeEvent.BUTTON_MIDDLE) {
				return true;
			} else {
				return false;
			}
		}
		
		case BUTTON_RIGHT: {
			if (controller.getButton()==NativeEvent.BUTTON_RIGHT) {
				return true;
			} else {
				return false;
			}
		}
		
		}
		
		return false;
	}
	
	@Override
	public void onDragEnd(DragController controller) {
		DOM.releaseCapture(controller.getHandler().getElement());
		controller.stopEventPropagation();
	}

	@Override
	public void onDragMove(DragController controller) {
		controller.stopEventPropagation();
	}

	@Override
	public void onDragStart(DragController controller) {
		DOM.setCapture(controller.getHandler().getElement());
		controller.stopEventPropagation();
	}

}
